package com.mallcloud.mall.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.product.api.dto.SpuTagDTO;
import com.mallcloud.mall.product.api.dto.SpuTagReferenceDTO;
import com.mallcloud.mall.product.api.entity.SpuTagReferenceModel;
import com.mallcloud.mall.product.api.vo.SpuTagReferenceVO;
import com.mallcloud.mall.product.service.SpuTagReferenceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "商品分组标签关联信息管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/product/spuTagReference")
public class SpuTagReferenceController {
    private final SpuTagReferenceService spuTagReferenceService;

    @ApiOperation("查询关联商品")
    @GetMapping("/referenceSpu")
    public R<List<SpuTagReferenceVO>> referenceSpu(SpuTagDTO dto) {
        return R.ok(spuTagReferenceService.referenceSpu(dto));
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public R<Boolean> updateById(@Validated @RequestBody SpuTagReferenceDTO dto) {
        return R.ok(spuTagReferenceService.updateSpuTagReference(dto));
    }


    @ApiOperation("分页查询")
    @GetMapping("/page")
    public R<IPage<SpuTagReferenceModel>> page(Page page, SpuTagReferenceModel dto) {
        return R.ok(spuTagReferenceService.page(page, Wrappers.query(dto)));
    }

    @ApiOperation("列表查询")
    @GetMapping("/list")
    public R<List<SpuTagReferenceModel>> list(SpuTagReferenceModel dto) {
        return R.ok(spuTagReferenceService.list(Wrappers.query(dto)));
    }

    @ApiOperation("通过id查询")
    @GetMapping("/getInfo")
    public R<SpuTagReferenceModel> getInfo(SpuTagReferenceModel dto) {
        return R.ok(spuTagReferenceService.getById(dto.getReferenceId()));
    }

    @ApiOperation("新增")
    @PostMapping("/save")
    public R<Boolean> save(@RequestBody SpuTagReferenceModel dto) {
        return R.ok(spuTagReferenceService.save(dto));
    }

    @ApiOperation("修改")
    @PostMapping("/update2")
    public R<Boolean> updateById(@RequestBody SpuTagReferenceModel dto) {
        return R.ok(spuTagReferenceService.updateById(dto));
    }

    @ApiOperation("删除")
    @DeleteMapping("/{referenceId}")
    public R<Boolean> removeById(@PathVariable Integer referenceId) {
        return R.ok(spuTagReferenceService.removeById(referenceId));
    }

    @ApiOperation("批量删除商品分组标签关联信息")
    @DeleteMapping
    public R<Boolean> removeByIds(@RequestBody List<Long> referenceIds) {
        return R.ok(spuTagReferenceService.removeByIds(referenceIds));
    }
}
